package com.study.security.core.social.qq.config;

import com.study.security.core.properties.SecurityProperties;
import com.study.security.core.social.SecurityConnectView;
import com.study.security.core.social.SocialAutoConfigurerAdapter;
import com.study.security.core.social.qq.connect.QQConnectFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.social.connect.ConnectionFactory;
import org.springframework.web.servlet.View;

/**
 * @author liyongkui
 */
@Configuration
@ConditionalOnProperty(prefix = "security.social.qq",name = "appId")
public class QQAutoConfig extends SocialAutoConfigurerAdapter {

    @Autowired
    private SecurityProperties securityProperties;

    @Override
    protected ConnectionFactory<?> createConnectionFactory() {
        return new QQConnectFactory(securityProperties.getSocial().getQq().getProviderId(),
                securityProperties.getSocial().getQq().getAppId(),securityProperties.getSocial().getQq().getAppSecret());
    }

    @Bean({"connect/qqConnected","connect/qqConnect"})
    @ConditionalOnMissingBean(name = "qqConnectedView")
    public View qqConnectedView(){
        return new SecurityConnectView();
    }
}
